import {axios} from 'taro-axios';
import  viewUtil from '../utils/viewUtil';

const api = {

  async get(url, data) {
    try {
      viewUtil.ShowLoading(true,"请求数据中...")
      let res = await axios.get(url, {params: data});
      res = res.data;
      return new Promise((resolve) => {
        viewUtil.ShowLoading(false)
        resolve(res);
      });
    } catch (err) {
      // alert('服务器出错');

    }
  },


  async post(url, data,headers) {
    try {
      viewUtil.ShowLoading(true,"请求数据中...")
      let res = await axios.post(url, data,headers);
      res = res.data;
      return new Promise((resolve) => {
        viewUtil.ShowLoading(false)
        resolve(res);
      });
    } catch (err) {
      // alert('服务器出错');
      console.log(err);
    }
  },
};

export default api;
